﻿using Dapper.DBContext.Schema;
using Guoc.BigMall.Infrastructure;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Guoc.BigMall.Domain.Entity
{  
    public class DistributeOrderItem:BaseEntity
    {
        public DistributeOrderItem() {
            this.CreatedOn = DateTime.Now;
            this.UpdatedOn = this.CreatedOn;
            this.CashStatus = MemberCashStatus.UnCash;
        }

        public int DistributeOrderId { get; set; }

        public int MemberId { get; set; }
        /// <summary>
        ///  收益层级
        /// </summary>
        public  int ProfitLevel { get; set; }

        /// <summary>
        /// 收益金额
        /// </summary>
        public decimal ProfitAmount { get; set; }

        /// <summary>
        ///  提现状态
        /// </summary>
        public MemberCashStatus CashStatus { get; set; }

        public DateTime CreatedOn { get; set; }

        public DateTime UpdatedOn { get; set; }


        /// <summary>
        ///  已提现
        /// </summary>
        public void Cashed() {
            if (this.CashStatus != MemberCashStatus.UnCash) {
                throw new FriendlyException("当前状态不是未提现");
            }
            this.CashStatus = MemberCashStatus.Cashed;
            this.UpdatedOn = DateTime.Now;

        }

        public bool CashedByFinance()
        {
            if (this.CashStatus == MemberCashStatus.UnCash)
            {
                this.CashStatus = MemberCashStatus.Finance;
                this.UpdatedOn = DateTime.Now;
                return true;
            }
            else {
                return false;
            }
           
        }

    }

    public enum MemberCashStatus {
        [Description("未提现")]
        /// <summary>
        ///  未提现
        /// </summary>
        UnCash =1,
        [Description("已提现")]
        Cashed =2,
        [Description("已打款")]
        Finance =3
    }
}
